﻿/*************************************************************************
File:   as/LoadZones.as
Author: Duykham
UpDate: 20/09/2006
TODO:   Load zones (cameras) to publish
/*************************************************************************/
echo("#included: LoadZones_S1.as");
///////////////////////////////////////////////////////////////////////////
//TODO: included files
///////////////////////////////////////////////////////////////////////////
//TODO:ExternalInterface
import flash.external.*;
///////////////////////////////////////////////////////////////////////////
//TODO: Setup External method to be called outside of Flash
var methodSetup:Boolean = ExternalInterface.addCallback("putCam", null, putCam);
var methodSetup:Boolean = ExternalInterface.addCallback("loadZones", null, loadZones);
var methodSetup:Boolean = ExternalInterface.addCallback("setCamValue", null, setCamValue);
///////////////////////////////////////////////////////////////////////////
//TODO:
//var cameras:Array = new Array ();
var square:Array = new Array();
var twoSquare:Array = new Array();
var twoCam:Array = new Array();
var threeSquare:Array = new Array();
var fourSquare:Array = new Array();
var nameArray:Array = new Array();
//twoCam
twoCam.push({x_value:45, y_value:120});
twoCam.push({x_value:240, y_value:120});
//twoSquare
twoSquare.push({x_value:45, y_value:95});
twoSquare.push({x_value:240, y_value:95});
twoSquare.push({x_value:45, y_value:295});
twoSquare.push({x_value:240, y_value:295});
//threeSquare
threeSquare.push({x_value:26, y_value:115});
threeSquare.push({x_value:135, y_value:205});
threeSquare.push({x_value:245, y_value:295});
threeSquare.push({x_value:26, y_value:115});
threeSquare.push({x_value:135, y_value:205});
threeSquare.push({x_value:245, y_value:295});
threeSquare.push({x_value:26, y_value:115});
threeSquare.push({x_value:135, y_value:205});
threeSquare.push({x_value:245, y_value:295});
//Chon vi tri chop cac camera
function putCam() {
	echo("soCamloadZones: "+soCam);
	echo("putCam");
	if (soCam == 1) {
		square.push({x_value:110, y_value:200});
	}
	if (soCam == 2) {
		square = twoCam;
		//thi vi tri cac Camera tren man hinh la 1 hang 2 cameras
	}
	if (soCam>2 && soCam<=4) {
		//neu so cam nho hon 4
		square = twoSquare;
		//thi vi tri cac Camera tren man hinh la o vuong 2x2
		echo("soCamloadZones: "+soCam);
	}
	if (soCam>4 && soCam<=9) {
		//neu so cam nho hon 9
		square = threeSquare;
		//thi vi tri cac Camera tren man hinh la o vuong 3x3
	}
	echo("square[0].x_value: "+square[0].x_value);
}
///////////////////////////////////////////////////////////////////////////
//TODO:
function loadZones() {
	echo("loadZones = function ()");
	for (i=0; i<soCam; i++) {
		//lan luot load Camera vao cac vi tri duoc dinh san
		var thisMC:MovieClip = _level0.createEmptyMovieClip("cam"+i+"_mc", i);
		//trace("nameArray["+i+"]: "+nameArray[i]);
		echo("thisMC: "+thisMC);
		thisMC._x = square[i].x_value;
		echo("square [i].x_value: "+square[i].x_value);
		thisMC._y = square[i].y_value;
		//thisMC.cam_txt.text = camArray [i].label;
		//newCamera = camArray[i].label;//lay ten Camera tu mang camArray
		thisMC.loadMovie("publishCam.swf");
		echo("loadMovie successfull!!!");
		//thisMC.newCamera = camArray[i].label;//lay ten Camera tu mang camArray
		//loadZone(thisMC, nameArray[i], 1, 50);
		echo("camArray [i].label: "+camArray[i].label);
	}
}
//loadZones ();
function setCamValue() {
	echo("setCamValue()");
	intervalID = setInterval(function () {
		/*
		_level0.cam0_mc.cam_txt.text = camArray [0].label;
		_level0.cam0_mc.display_txt.text = camArray [0].displayName;
		//cam0_mc.camName = camArray[0].label;
		_level0.cam0_mc.camID_txt.text = camArray [0].data;
		_level0.cam0_mc.motion_txt.text = camArray [0].motion;
		_level0.cam0_mc.priority_txt.text = camArray [0].priority;
		//cam0_mc.camNumber = camArray[0].data;
		_level0.cam1_mc.cam_txt.text = camArray [1].label;
		_level0.cam1_mc.display_txt.text = camArray [1].displayName;
		echo ("_level0.cam1_mc.cam_txt.text: " + _level0.cam1_mc.cam_txt.text);
		echo ("camArray [1].label;: " + camArray [1].label);
		_level0.cam1_mc.camID_txt.text = camArray [1].data;
		_level0.cam1_mc.motion_txt.text = camArray [1].motion;
		_level0.cam1_mc.priority_txt.text = camArray [1].priority;
		_level0.cam2_mc.cam_txt.text = camArray [2].label;
		_level0.cam2_mc.display_txt.text = camArray [2].displayName;
		_level0.cam2_mc.camID_txt.text = camArray [2].data;
		_level0.cam2_mc.motion_txt.text = camArray [2].motion;
		_level0.cam2_mc.priority_txt.text = camArray [2].priority;
		_level0.cam3_mc.cam_txt.text = camArray [3].label;
		_level0.cam3_mc.display_txt.text = camArray [3].displayName;
		_level0.cam3_mc.camID_txt.text = camArray [3].data;
		_level0.cam3_mc.motion_txt.text = camArray [3].motion;
		_level0.cam3_mc.priority_txt.text = camArray [3].priority;
		*/
		setValue(_level0.cam0_mc, 0);
		setValue(_level0.cam1_mc, 1);
		setValue(_level0.cam2_mc, 2);
		setValue(_level0.cam3_mc, 3);
	}, 100);
}
//Neu su dung nhung cau lenh duoi day thi cac thuoc tinh cua Camera se bi mat
//do do khi exit khong the quay tro ve duoc
//nhung chuong trinh chay se nhe hon!!! 
//update: 20061002: van su dung nhung cac thuoc tinh cua camera van khong bi mat =>GOOD!
this.onEnterFrame = function() {
	if (_level0.cam0_mc.display_txt.text != undefined && _level0.cam0_mc.display_txt.text != "") {
		clearInterval(intervalID);
	}
};
/*
//for Test in flash (without VB)
putCam();
loadZones();
setCamValue();
*/
//
setValue = function (myMovie:MovieClip, num:Number) {
	trace("setValue: "+num);
	var j = num;
	myMovie.cam_txt.text = camArray[j].label;
	myMovie.display_txt.text = camArray[j].displayName;
	myMovie.camID_txt.text = camArray[j].data;
	myMovie.motion_txt.text = camArray[j].motion;
	myMovie.priority_txt.text = camArray[j].priority;
	if (CFG.autoStart==1)
	{
		myMovie.next_btn.onRelease();
	}
	
};
